<?php include('header.php'); ?>
<?php include('side.php'); ?>
<div class="layui-body">
	<fieldset class="layui-elem-field layui-field-title" style="margin: 20px 0;">
		<legend><?= Lang::app('entry') ?><span style="color: #BBA;font-size: 14px"></legend>
	</fieldset>
	<div class="layui-container">
		<div class="layui-row">
			<div class="layui-col-md9">
				<form class="layui-form layui-form-pane" lay-filter="entry-data" action="" onsubmit="return false;">
					<input name="id" lay-filter="id" type="hidden" value="<?= isset($data['id']) ? $data['id'] : 0 ?>" />
					<div class="layui-form-item">
						<label class="layui-form-label"><?= Lang::app('name') ?></label>
						<div class="layui-input-inline">
							<input lay-filter="name" type="text" name="name" autocomplete="off" placeholder="<?= Lang::app('msg_name') ?>" class="layui-input" value="<?= isset($data['name']) ? $data['name'] : '' ?>" />
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label"><?= Lang::app('mobile') ?></label>
						<div class="layui-input-inline">
							<input lay-filter="mobile" type="text" name="mobile" autocomplete="off" placeholder="<?= Lang::app('msg_mobile') ?>" class="layui-input" value="<?= isset($data['mobile']) ? $data['mobile'] : '' ?>" />
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label"><?= Lang::app('inviter') ?></label>
						<div class="layui-input-inline">
							<input lay-filter="inviter" type="text" name="inviter" autocomplete="off" placeholder="<?= Lang::app('msg_inviter') ?>" class="layui-input" value="<?= isset($data['inviter']) ? $data['inviter'] : '' ?>" />
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label"><?= Lang::app('token') ?></label>
						<div class="layui-input-block">
							<input lay-filter="token" type="text" name="token" autocomplete="off" size="10" placeholder="<?= Lang::app('msg_token') ?>" class="layui-input" value="<?= isset($data['token']) ? $data['token'] : '' ?>" />
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-input-inline">
							<div class="layui-inline">
								<?php if (isset($data['id'])) { ?>
									<button name="edit" class="layui-btn layui-btn-normal"><?= Lang::app(['edit', 'record']) ?></button>
								<?php } else { ?>
									<button name="entry" class="layui-btn layui-btn-normal"><?= Lang::app(['add', 'record']) ?></button>
								<?php } ?>
								
							</div>
							<div class="layui-inline">
								<button name="clear" class="layui-btn layui-btn-normal"><?= Lang::app('clear') ?></button>
							</div>
						</div>
					</div>
				</form>
				
					
			</div>
		</div>
	</div>
</div>

<script>
$('input[name="name"]').focus();

layui.use('form', function(){
	var form = layui.form;
	form.render();
	
	$('button[name="entry"]').click(function() {
		var postdata = form.val('entry-data');
		if ($('input[name="name"]').val() != '') {
			windos.ajaxPost('/site/add_user', postdata, function(res) {
				if (res.code == 1) {
						layer.msg('操作成功');
						$('input[type="text"]').val('');
						$('input[name="name"]').focus();
					} else if (res.code == 2) {
						layer.msg('该邀请码已被使用');
					} else {
						layer.msg('操作失败');
					}
			});
		} else {
			layer.msg('姓名必填');
		}
	});
	
	$('button[name="edit"]').click(function() {
		var postdata = form.val('entry-data');
		if ($('input[name="name"]').val() != '') {
			windos.ajaxPost('/site/edit_user', postdata, function(res) {
				if (res.code == 1) {
						layer.msg('操作成功');
					} else if (res.code == 2) {
						layer.msg('该邀请码已被使用');
					} else {
						layer.msg('操作失败');
					}
			});
		} else {
			layer.msg('姓名必填');
		}
	});
	
	$('button[name="clear"]').click(function() {
		$('input[type="text"]').val('');
	});
	
	//回车事件
	$('.layui-input').each(function(i){
		var _this = $(this);
		_this.bind('keypress', function(event) {
			if (event.keyCode == 13) {
				$('.layui-input').eq(i + 1).focus();
				return false;
			}
		});
	});
	
	

});

	
</script>

<?php include('footer.php'); ?>

